using Engine;
using Game;

namespace SCIENEW {
    /// <summary>
    /// 流体系统的基本单元
    /// </summary>
    public abstract class FluidTransferrer {
        public Point3 Position;
        public SubsystemTerrain SubsystemTerrain;
        public ITank Tank;

        public FluidTransferrer(Point3 position, SubsystemTerrain subsystemTerrain) {
            Position = position;
            SubsystemTerrain = subsystemTerrain;
        }

        /// <summary>
        /// 获取流体储存实体
        /// </summary>
        /// <returns></returns>
        public virtual ITank GetTank() {
            if (DeviceEntityUtils.GetDeviceEntity(SubsystemTerrain, Position, out ComponentBlockEntity componentBlockEntity)) {
                ComponentTankBase tank1 = componentBlockEntity.Entity.FindComponent<ComponentTankBase>();
                ComponentInventoryTankBase tank2 = componentBlockEntity.Entity.FindComponent<ComponentInventoryTankBase>();
                if (tank1 != null)
                    return tank1;
                return tank2;
            }
            return null;
        }

        public virtual bool IsFull(ITank tank) {
            return tank.GetTankVolume(0) >= tank.GetTankOriginalCapacity(0);
        }

        public virtual int RemoveFluid(ITank tank, float volume, out float removedVolume, out int removedTankIndex) {
            removedVolume = 0f;
            removedTankIndex = 0;
            return 0;
        }

        public virtual int GetFluidValue(ITank tank) {
            return tank.GetTankValue(0);
        }

        public virtual float AcquireFluid(ITank tank, float volume, int fluidValue) {
            return ComponentFluidTank.AcquireFluid(tank, fluidValue, volume);
        }

        public virtual void OnAdded() {

        }

        public virtual void OnRemoved() {

        }

        public virtual void Simulate(float dt) {

        }
    }
}